package com.ymt.bpm.util.w3cdom;

import java.math.BigDecimal;

public class NumberScaleAttrFilter implements AttrFilter {
	
	public NumberScaleAttrFilter() {}
	
	public NumberScaleAttrFilter(int scale) {
		this.scale = scale;
	}
	
	/**
	 * 精度
	 */
	private int scale = 1;

	@Override
	public String translate(String attrValue) {
		try {
			BigDecimal b = new BigDecimal(attrValue);
			return b.setScale(scale, BigDecimal.ROUND_HALF_UP).toPlainString();
		} catch(Exception e) {
			e.printStackTrace();
		}
		return "0";
	}

}
